#{extends 'CRUD/layout.html' /}
#{set title:messages.get('medicationDetail.edit') /}

<div id="crudShow" class="${type.name}">

    <h2 id="crudShowTitle">&{'medicationDetail.edit'}</h2>

    <div class="objectForm">
    #{form action:@save(object._key()), enctype:'multipart/form-data'}
        #{crud.form fields:['medicationDetailName', 'medication', 'insertions', 'allergens']}
        	#{crud.custom 'insertions'}
        		<label for="${insertions}">&{'insertions'}</label>
        		<select id="${insertionsSelector}" multiple="yes" name="object.insertions.insertionId" style="min-width: 280px;">
        			#{list items:models.Insertion.findAll(), as:'insertion'}
        				<option value=${insertion.insertionId} ${object.insertions.contains(insertion) ? 'selected' : ''}>${insertion.insertionName}</option>
        			#{/list}
        		</select>
        	#{/crud.custom}
        	#{crud.custom 'allergens'}
        		<label for="${allergens}"><a href="@{Allergens.list()}" class="nonUnderlined">&{'objects.allergens'}</a></label>
	    		%{allergens = models.Allergen.find("byMedicationDetail", object).fetch()}%
	    		#{if allergens != null && !allergens.isEmpty() }
    			<div class="list">
					#{list items:allergens, as:'allergen'}
						<li>
							<span id="${allergen.allergenId}" class="hiddenLinks">
								@{Allergens.show(allergen.allergenId)}
					        </span>
				        	${allergen.allergenName}
				        </li>
				    #{/list}
			    </div>
	    		#{/if}
	    		#{else}
					&{'crud.list.empty'}	    		
	    		#{/else}
        	#{/crud.custom}
        #{/crud.form}
        <p class="crudButtons">
            <input type="submit" name="_save" value="&{'crud.save', type.modelName}" />
            <input type="submit" name="_saveAndContinue" value="&{'crud.saveAndContinue', type.modelName}" />
        </p>
    #{/form}
    </div>

    #{form @delete(object._key())}
        <p class="crudDelete">
            <input type="submit" value="&{'medicationDetail.delete'}" onclick="return confirm('&{'medicationDetail.delete'}')"/>
        </p>
    #{/form}

</div>